package excel;

import sql.MysqlDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * todo
 *
 * @author zhengshan
 * @Date 2023/1/10 11:23
 */
public class TestDemoTwo {

    public static void main(String[] args) {

        MysqlDemo mysqlDemo = new MysqlDemo();

        List<DwbiDtoMenuInfo> dwbiDtoMenuInfos = mysqlDemo.querySheetInfo();

        Map<String, List<DwbiDtoMenuInfo>> map = dwbiDtoMenuInfos.stream().collect(Collectors.groupingBy(DwbiDtoMenuInfo::getMenuCode));

        for(Map.Entry<String, List<DwbiDtoMenuInfo>> entry : map.entrySet()){

            List<DwbiDtoMenuInfo> dwbiDtoMenuInfoList = entry.getValue();
            int i = 0;
            DwbiDtoMenuInfo ss = new DwbiDtoMenuInfo();
            for(DwbiDtoMenuInfo dwbiDtoMenuInfo : dwbiDtoMenuInfoList){
                if(null != dwbiDtoMenuInfo.getMcItemcode()){
                    ss.setMcName(dwbiDtoMenuInfo.getMcName());
                    ss.setMcItemcode(dwbiDtoMenuInfo.getMcItemcode());
                    ss.setMcBrand(dwbiDtoMenuInfo.getMcBrand());
                    ss.setsProductCode(dwbiDtoMenuInfo.getsProductCode());
                    i++;
                }
            }
            if(i == 1){

                for(DwbiDtoMenuInfo dwbiDtoMenuInfo : dwbiDtoMenuInfoList){
                    dwbiDtoMenuInfo.setMcName(ss.getMcName());
                    dwbiDtoMenuInfo.setMcItemcode(ss.getMcItemcode());
                    dwbiDtoMenuInfo.setMcBrand(ss.getMcBrand());
                    dwbiDtoMenuInfo.setsProductCode(ss.getsProductCode());
                    mysqlDemo.insertMenu(dwbiDtoMenuInfo.toString());

                }
            }else{
                for(DwbiDtoMenuInfo dwbiDtoMenuInfo : dwbiDtoMenuInfoList){
                    mysqlDemo.insertMenu(dwbiDtoMenuInfo.toString());
                }
            }

        }
    }
}
